﻿//using System;
//using System.Drawing;
//using System.Drawing.Imaging; 

//namespace NudaJeFuc.WebUI.Classes
//{
//   public class Images
//   {
//      /// <summary>
//      /// Resize image proportianally. 
//      /// </summary>
//      /// <param name="src">Source file</param>
//      /// <param name="maxWidth"></param>
//      /// <param name="maxHeight"></param>
//      /// <returns></returns>
//      public Bitmap ProportionallyResizeBitmap(Bitmap src, int maxWidth = 132, int maxHeight = 122)
//      {
//         // original dimensions
//         int w = src.Width;
//         int h = src.Height;

//         // Longest and shortest dimension
//         int longestDimension = (w > h) ? w : h;
//         int shortestDimension = (w < h) ? w : h;

//         // proportionality
//         float factor = ((float)longestDimension) / shortestDimension;

//         // default width is greater than height
//         double newWidth = maxWidth;
//         double newHeight = maxWidth / factor;

//         // if height greater than width recalculate
//         if (w < h)
//         {
//            newWidth = maxHeight / factor;
//            newHeight = maxHeight;
//         }

//         // Create new Bitmap at new dimensions
//         Bitmap result = new Bitmap((int)newWidth, (int)newHeight);
//         using (Graphics g = Graphics.FromImage((System.Drawing.Image)result))
//            g.DrawImage(src, 0, 0, (int)newWidth, (int)newHeight);
//         return result;
//      }
//       /// <summary>
//       /// Create thumbnail image for file
//       /// </summary>
//       /// <param name="sourceFileName">Source file</param>
//       /// <param name="lnWidth">resize to width</param>
//       /// <param name="lnHeight">resize to height</param>
//       /// <returns>Resized image</returns>
//      public static Bitmap CreateThumbnail(string sourceFileName, int lnWidth, int lnHeight)
//      {
//          System.Drawing.Bitmap bmpOut = null;

//          try
//          {
//              System.Drawing.Bitmap loBMP = new Bitmap(sourceFileName);
//              ImageFormat loFormat = loBMP.RawFormat;

//              decimal lnRatio;
//              int lnNewWidth = 0;
//              int lnNewHeight = 0;

//              //*** If the image is smaller than a thumbnail just return it
//              if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)

//                  return loBMP;

//              if (loBMP.Width > loBMP.Height)
//              {
//                  lnRatio = (decimal)lnWidth / loBMP.Width;
//                  lnNewWidth = lnWidth;
//                  decimal lnTemp = loBMP.Height * lnRatio;
//                  lnNewHeight = (int)lnTemp;
//              }

//              else
//              {
//                  lnRatio = (decimal)lnHeight / loBMP.Height;
//                  lnNewHeight = lnHeight;
//                  decimal lnTemp = loBMP.Width * lnRatio;
//                  lnNewWidth = (int)lnTemp;
//              }


//              ////System.Drawing.Image imgOut = loBMP.GetThumbnailImage(lnNewWidth,lnNewHeight,null,IntPtr.Zero);
//              //// *** This code creates cleaner (though bigger) thumbnails and properly
//              //// *** and handles GIF files better by generating a white background for
//              //// *** transparent images (as opposed to black)

//              bmpOut = new Bitmap(lnNewWidth, lnNewHeight);

//              Graphics g = Graphics.FromImage(bmpOut);
//              g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
//              g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
//              loBMP.Dispose();
//          }

//          catch (Exception)
//          {
//              return null;
//          }

//          return bmpOut;
//      }     
//   }
//}